<?php include  APP_PATH.'../template/public/header.php'?>
<aside class="main-sidebar">
    <section class="sidebar">
        <?php include APP_PATH.'../template/public/navigation.php'?>
    </section>
</aside>
<div class="content-wrapper">
    <section class="content-header">
        <h1>
            {$title}
            <a href="{:url('add_sidcol')}" type="button" class="btn btn-sm btn-primary" >添加栏目</a>
        </h1>

        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> {$title}</a></li>
        </ol>
    </section>
    <section class="content">

        <div class="box">
            <div class="box-body">
                <table id='table'
                       data-url="{:url('getsidecolumn')}"
                       data-toggle="table"
                       data-show-refresh="true"
                       data-show-toggle="true"
                       data-show-columns="true"
                       data-search="true"
                       data-query-params="queryParams"
                       data-advanced-search="true"
                       data-side-pagination="server"
                       data-select-item-name="worker_picker"
                       data-show-export="true"
                       data-click-to-select="true"
                       data-toolbar="#toolbar"
                       data-sort-name="name"
                       data-sort-order="desc">
                    <div class="bars pull-left">

                        <div id="toolbar">
                            <div class="form-group" >
                                <select id="role" name="role" class="form-control" style="width: 100%;" tabindex="-1" aria-hidden="true">
                                    <option value="all">全部</option>
                                    <option value="0">管理员</option>
                                    <option value="1">代理商</option>
                                    <option value="2">子账户</option>
                                    <option value="3">广告主</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <thead>
                    <tr>
                        <th data-field="name"  data-align="left" data-sortable="true" >栏目名称</th>
                        <th data-field="url"   data-align="left">链接</th>
                        <th data-field="fu_name"  data-align="left" data-sortable="true" >父类栏目名称</th>
                        <th data-field="state"  data-align="center">是否显示</th>
                        <th data-field="sort"   data-align="left">排序</th>
                        <th data-field="role"   data-align="left">角色</th>
                        <th data-field="level"   data-align="left">等级</th>
                        <th data-field="operation"   data-align="left">操作</th>
                    </tr>

                    </thead>
                    <tbody>

                    </tbody>
                </table>
            </div>
        </div>
    </section>
</div>
<?php include APP_PATH.'../template/public/footer.php'; ?>
<script>
    function queryParams(params) {
        return {
            limit: params.limit,
            offset: params.offset,
            search:$('.search input[type="text"]').val(),
            name: params.sort,
            order: params.order,
            role:$("#role").val()
        };
    }
    $("#role").change(function () {
        var role=$("#role").val();
        var loading = layer.load(1, {shade: [0.1, '#fff']});
        $.get("{:url('getsidecolumn')}?&role="+role ,function(data){
            layer.close(loading);
            if(data.length == 0)
            {
                alert("页面数据为空,请选择其他项");
                return ;
            }
            $('#table').bootstrapTable("load",data);
        });
    });
    function del_fun(id,level) {
        var loading = layer.load(1, {shade: [0.1, '#fff']});
        $.get("{:url('del_fun')}?id="+id+'&level='+level,function (res) {
            layer.close(loading);
            if (res.code > 0) {
                layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                    var role=$("#role").val();
                    var loading = layer.load(1, {shade: [0.1, '#fff']});
                    $.get("{:url('getsidecolumn')}?&role="+role, function(data){
                        layer.close(loading);
                        if(data.length == 0)
                        {
                            alert("页面数据为空,请选择其他项");
                            return ;
                        }
                        $('#table').bootstrapTable("load",data);
                    });
                });
            } else {
                layer.msg(res.msg, {time: 1800, icon: 2});
            }

        })
    }
    function edit_state(id,level,val){
        var loading = layer.load(1, {shade: [0.1, '#fff']});
        $.get("{:url('edit_state')}?id="+id+'&level='+level+'&state='+val,function (res) {
            layer.close(loading);
            if (res.code > 0) {
                layer.msg(res.msg, {time: 800, icon: 1}, function () {
                    var role=$("#role").val();
                    var loading = layer.load(1, {shade: [0.1, '#fff']});
                    $.get("{:url('getsidecolumn')}?&role="+role, function(data){
                        layer.close(loading);
                        if(data.length == 0)
                        {
                            alert("页面数据为空,请选择其他项");
                            return ;
                        }
                        $('#table').bootstrapTable("load",data);
                    });
                });
            } else {
                layer.msg(res.msg, {time: 1800, icon: 2});
            }
        })
    }
    function edit_sort(id,level,val){
        var loading = layer.load(1, {shade: [0.1, '#fff']});
        $.get("{:url('edit_sort')}?id="+id+'&level='+level+'&sort='+val,function (res) {
            layer.close(loading);
            if (res.code > 0) {
                layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                    var role=$("#role").val();
                    var loading = layer.load(1, {shade: [0.1, '#fff']});
                    $.get("{:url('getsidecolumn')}?&role="+role, function(data){
                        layer.close(loading);
                        if(data.length == 0)
                        {
                            alert("页面数据为空,请选择其他项");
                            return ;
                        }
                        $('#table').bootstrapTable("load",data);
                    });
                });
            } else {
                layer.msg(res.msg, {time: 1800, icon: 2});
            }
        })
    }
</script>
</html>